package br.unicamp.mc715.order;

import java.io.Serializable;
import java.util.Vector;

import br.unicamp.mc715.transport.TransportId;

public class PingMessage implements Serializable {
	
	private static final long serialVersionUID = 4900314142691124070L;
	
	public int number;
	public TransportId senderId;
	public String msg;
	public Vector<Long> timestamp = new Vector<Long>();
	
	public PingMessage(int tam, int number, TransportId senderId) {
		
		this.number = number;
		this.senderId = senderId;
		msg = "";
		for (int i = 0; i < tam; i++)
			msg += "a";
	}
	
	public String toString() {
		String msg = "";
		
		for (Long ts : timestamp) {
			msg += ts + " ";
		}
		return msg;
	}

	public void append(Long ts) {
		timestamp.add(ts);
	}

	public double getLatency() {
		/* Return result of latency formula */
		return ((timestamp.get(3)-timestamp.get(0))-(timestamp.get(2)-timestamp.get(1)))/2000000.0;
	}

	public double getFirstTimestamp() {
		/* Return first timestamp of the message */
		return timestamp.get(0);
	}
	
}
